<script type="text/javascript">
function _load_css(href) {
    var t = document.createElement("link");
    t.setAttribute('type', 'text/css');
    t.setAttribute('rel', 'stylesheet');
    t.setAttribute('href', href);
    $("head")[0].appendChild(t);
}

$(function() {
    _load_css('/static/css/kissy-base-min.css');
    _load_css('/static/css/kissy-editor-pkg-min-datauri.css');
    $('#btn-cancel').click(function() {
        if (confirm('确认不保存退出？')) {
% if add:
            location.assign('/doc/${root_id}/${parent_id}');
% else:
            location.assign('/doc/${root_id}/${node.id}');
% endif
        }
    })
});

function check() {
    if ($.trim($('#title').val())=='') {
        $('#title').focus();
        $('#div-title').addClass('error');
        $('#div-title .help-inline').show();
        return false;
    }
    return true;
}
</script>

<div>
    <h3>
% if add:
Add new page:
% else:
Edit page:
% endif
    </h3>
    <form action="/${customer.domain}/${action}" method="post" onsubmit="return check()">
% if add:
        <input type="hidden" name="root_id" value="${root_id}" />
        <input type="hidden" name="parent_id" value="${parent_id}" />
% else:
        <input type="hidden" name="root_id" value="${root_id}" />
        <input type="hidden" name="id" value="${editing.id}" />
% endif
        <div id="div-title" class="control-group">
            <label class="control-label">标题：</label>
            <div class="controls">
                <input type="text" id="title" name="title" value="${editing.title|h}" placeholder="Enter the title" class="input-xlarge" />
                <span class="help-inline hide">标题不能为空</span>
            </div>
        </div>
        <label>Content:</label>
        <textarea id="editor" name="content" style="width:100%; height:400px; margin:0;">${editing.content}</textarea>
        <script src="http://a.tbcdn.cn/s/kissy/1.2.0/??kissy-min.js,uibase-min.js,component-min.js,dd-min.js,overlay-min.js,editor-min.js"></script>
        <script src="http://a.tbcdn.cn/s/kissy/1.2.0/editor/biz/ext/editor-plugin-pkg-min.js"></script>

<script type="text/javascript">
KISSY.ready(function(S) {

    S.use('editor', function() {

        var KE = KISSY.Editor;
        var cfg = {
            attachForm:true,
            baseZIndex:10000,
            //自定义样式
            //customStyle:"p{color:purple;}",
            //自定义外部样式
            //customLink:["http://localhost/customLink.css","http://xx.com/y2.css"],
            //是否一开始自动聚焦
            //focus:true,
            pluginConfig: {
                "font-family": {
                    items: [
                        { name: "宋体", value: "SimSun" },
                        { name: "黑体", value: "SimHei" },
                        { name: "楷体", value: "SimKai" },
                        
                        { name: "Georgia", value: "Georgia" },
                        { name: "Times New Roman", value: "Times New Roman" },
                        { name: "Courier New", value: "Courier New" },
                        { name: "Arial", value: "Arial" },
                        { name: "Verdana", value: "Verdana" },
                        { name: "Tahoma", value: "Tahoma" }
                    ]
                },
                //"draft":false,
                "image":{
                    upload:{
                        serverUrl:"/${customer.domain}/_upload/image",
                        surfix:"png,jpg,jpeg,gif",
                        fileInput:"file",
                        sizeLimit:1000,//k
                        extraHtml:""
                    }
                },
                //"flash":{
                //    defaultWidth:"300",
                //    defaultHeight:"300"
                //},
                //"font-size":false,
                //"font-family":false,
                //"font-bold":false,
                // "font-italic":false,
                //"font-underline":false,
                //"video":{
                //    urlCfg:[
                //        {
                //            reg:/tudou\.com/i,
                //            url:"http://bangpai.taobao.com/json/getTudouVideo.htm?" +
                //                    "url=@url@&callback=@callback@"//"&rand=@rand@"
                //        }
                //    ],
                //    urlTip:"请输入优酷网、土豆网、酷7网的视频播放页链接...",
                //    providers:[
                //        {
                //            reg:/youku\.com/i,
                //            width:480,
                //            height:400,
                //            detect:function(url) {
                //                var m = url.match(/id_([^.]+)\.html$/);
                //                if (m) {
                //                    return "http://player.youku.com/player.php/sid/" + m[1] + "/v.swf";
                //                }
                //                m = url.match(/v_playlist\/([^.]+)\.html$/);
                //                if (m) {
                //                    return;
                //                    //return "http://player.youku.com/player.php/sid/" + m[1] + "/v.swf";
                //                }
                //                return url;
                //            }
                //        },
                //        {
                //            reg:/tudou\.com/i,
                //            width:480,
                //            height:400,
                //            detect:function(url) {
                //                return url;
                //            }
                //        }
                //    ]
                //},
                "resize":{
                    direction:["y"]
                },

                dragupload:{
                    surfix:"png,jpg,jpeg,gif",
                    fileInput:"file",
                    sizeLimit:1000,
                    serverUrl:"/upload/img"
                }
            }
        };


        window.editor2 = KE("#editor", S.clone(cfg)).use("checkbox-sourcearea,format,font," +
                    "separator,color," +
                    "separator,removeformat,separator," +
                    "undo,separator," +
                    "list,indent," +
                    "justify,separator,link," +
                    "image,flash," +
                    "video," +
                    "separator,table,resize," +
                    "draft," +
                    "pagebreak,separator,maximize,dragupload");



    });
});

</script>
        <div class="form-actions">
            <button type="submit" class="btn btn-primary">Save</button>
            <button id="btn-cancel" type="button" class="btn">Cancel</button>
        </div>
    </form>
</div>
